﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.IO;
using System.Text;
using System.Web;
using System.Xml;

namespace BlogExtractor {
	class Web {
		NetworkCredential _credentials;

		public Exception Exception { get; set; }

		public Web() { }
		public Web(NetworkCredential c) { _credentials = c; }

		public static Stream Stream(string url) {
			var request = (HttpWebRequest)WebRequest.Create(url);
			if (Program.Profile.UseProxy) {
				request.UseDefaultCredentials = true;
				request.CookieContainer = new CookieContainer();
				request.AllowAutoRedirect = true;
			}
			using (var response = (HttpWebResponse)request.GetResponse()) {
				return response.GetResponseStream();
			}
		}


		public static string Content(string url) {
			string content = null;
			var request = (HttpWebRequest)WebRequest.Create(url);
			if (Program.Settings.UseProxy) {
				request.UseDefaultCredentials = true;
				request.CookieContainer = new CookieContainer();
				request.AllowAutoRedirect = true;
			}
			using (var response = (HttpWebResponse)request.GetResponse()) {
				using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"))) {
					content = reader.ReadToEnd();
				}
			}
			return content;
		}
		/*
		public static XmlContent(string url) {
			var xml = new XmlTextReader(url);
			xml.
		}
		 */
	}
}
